<?php
/*
File: prodman.php
Version: 2.0
Date created: 
Last Edited : 26-07-2008
Author: Craig G Smith<craig@joomla-host.co.za
*/

  defined( 'JOSCOM_VERSION' ) or die( 'Direct Access to this location is not allowed.' );
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      tep_db_connect() or die('Unable to connect to database server!');
    }
    global $category_links, $languages_id, $cPath, $cPath_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    require(DIR_WS_COMPONENT . 'includes/application_top.php');
  }
  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();
  include(DIR_WS_LANGUAGES . $language . '/categories.php');
$action = isset($_REQUEST['action'])?$_REQUEST['action']:'';

//ok we have a few steps to take in this event:
//here we put the ones without display:

switch($action){
//save etc



case "confirmdelete":
echo 'here we will find which checkboxes were checked and remove the products!!!<br>
      smple code here for the idea';

print_r($_POST);
$checkarr = array();
foreach($_POST['pid'] as $product){
$prodcatarr = explode(",", $product);
$prodid = $prodcatarr[0];
$catid = $prodcatarr[1];

//ok, let us now add the prodid to an array if it does not already exist
if(!in_array($prodid, $checkarr)){
$checkarr[] = $prodid;
}

//ok now delete it:::
$database->setQuery("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$prodid . "' and categories_id = '" . (int)$catid . "'");
$database->query();
$database->setQuery("delete from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . tep_db_input($prodid) . "' ");
$database->query();
//loop through all the articles....
}
//print_r($checkarr);

// ok foreach product in checkarr we do a count and see if it exists in the products to categories table, if not, we delete it from the products table, the products description table, etc...

foreach($checkarr as $product_id){
$product_categories_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "'");
          $product_categories = tep_db_fetch_array($product_categories_query);

          if ($product_categories['total'] == '0') {
            tep_remove_product($product_id);
          }

}
$url = tep_href_link("prodman.php", 'msg=' . TEXT_UPDATE_COMPLETE);
  tep_redirect($url);
break;
case "copyconfirm":
print_r($_POST);

foreach($_POST['copy'] as $key=>$ctype){
 //switch($ctype) {
 if($ctype == 2) {
 //1 lets make sure not duplicating in a category
  $check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$key . "' and categories_id = '" . (int)$_POST['categories_id'][$key] . "'");
              $check = tep_db_fetch_array($check_query);
              if ($check['total'] < '1') {
                //tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$categories_id . "')");
            //  }
 
 $database->setQuery("Insert into #__osc_products_to_categories values('$key','{$_POST['categories_id'][$key]}')");
 $database->query();
 }
// break;
 }elseif($ctype == 1){
 
 //case 1:
 $database->setQuery("Select * from #__osc_products where products_id = '$key'");
$result = $database->loadObjectList();
$thisprod = $result[0];
foreach($thisprod as $pkey=>$value){
$$pkey = $value;
}
$sql_data_array = array('products_quantity' => $products_quantity,
                                  'products_model' => $products_model,
                                  'Featured_product' => $Featured_product,
                                  'products_price' => $products_price,	
                                  'products_date_available' => $products_date_available,
                                  'products_weight' => $products_weight,
                                  'products_status' => $products_status,
                                  'products_tax_class_id' => $products_tax_class_id,
                                  'manufacturers_id' => $manufacturers_id,
                                  'products_length' => $products_length,
                                  'products_width' => $products_width,
                                  'products_depth' => $products_depth,
                                  'vendors_prod_id' => $vendors_prod_id,
                                  'vendors_product_price' => $vendors_product_price,
                                  'vendors_id' => $vendors_id,
                                  'vendors_prod_comments' => $vendors_prod_comments,
                                  'products_hide_from_groups' => $products_hide_from_groups,
                                  'supplier_id' => $vendors_id,
                                  'suppliers_id' => $products_suppliers_id,
                                  'affiliate_allow_product' => $affiliate_allow_product,
                                  'products_price1' => $products_price1,
                                  'products_price2' => $products_price2,
                                  'products_price3' => $products_price3,
                                  'products_price4' => $products_price4,
                                  'products_price5' => $products_price5,
                                  'products_price6' => $products_price6,
                                  'products_price7' => $products_price7,
                                  'products_price8' => $products_price8,
                                  'products_price1_qty' => $products_price1_qty,
                                  'products_price2_qty' => $products_price2_qty,
                                  'products_price3_qty' => $products_price3_qty,
                                  'products_price4_qty' => $products_price4_qty,
                                  'products_price5_qty' => $products_price5_qty,
                                  'products_price6_qty' => $products_price6_qty,
                                  'products_price7_qty' => $products_price7_qty,
                                  'products_price8_qty' => $products_price8_qty,
                                  'products_qty_blocks' => $products_qty_blocks,
                                  'products_date_available' => $products_date_available,
                                  'products_image' => $products_image,
                                  'products_fileupload' => $products_fileupload,
                                  'products_vidupload' => $products_vidupload,
                                  'products_mp3' => $products_mp3,
                                  'products_pdfupload' => $products_pdfupload,
                                  'products_date_added' => $products_date_added,
                                  'products_last_modified' => $products_last_modified,
                                  'customer_id' => $customer_id,
                                  'products_ordered' => $products_ordered,
                                  'cost_price' => $cost_price,
                                  'products_price_myself' => $products_price_myself                                
                                  
                                  );
               //insert and get a prodid!!!                   
tep_db_perform(TABLE_PRODUCTS, $sql_data_array);
            $products_id = tep_db_insert_id();

$sub_query = tep_db_query("select  price_period, oneday_price, days_as_period, pay_period_type  from " . TABLE_SUBSCRIPTIONS . " where productid = '" . tep_db_input($key) . "'");
            $sub = tep_db_fetch_array($sub_query);
            tep_db_query("INSERT INTO " . TABLE_SUBSCRIPTIONS . " (productid, pay_period_type, price_period, oneday_price, days_as_period, pay_dates) VALUES ( '$products_id', '" . $sub['pay_period_type'] . "', '" . $sub['price_period'] . "', '" . $sub['oneday_price'] . "', '" . $sub['days_as_period'] . "', NULL)");

            $description_query = tep_db_query("select language_id, products_name, products_description, products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$key. "'");
            while ($description = tep_db_fetch_array($description_query)) {
              tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url, products_viewed) values ('" . (int)$products_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['products_name']) . "', '" . tep_db_input($description['products_description']) . "', '" . tep_db_input($description['products_url']) . "', '0')");
            } 
            
            tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$_POST['categories_id'][$key] . "')");
            
                 
  $database->setQuery("Select * from " . TABLE_PRODUCTS_GROUPS . " where products_id = '$key' and customers_group_id > '0' order by customers_group_id");
  $cgrpricing = $database->loadObjectList();
  foreach($cgrpricing as $tpg){
  
            tep_db_query("insert into " . TABLE_PRODUCTS_GROUPS . " (customers_group_id,customers_group_price,  products_id,  products_price1,  products_price2,  products_price3,  products_price4,  products_price5,  products_price6,  products_price7,  products_price8,  products_price1_qty,  products_price2_qty,  products_price3_qty,  products_price4_qty,  products_price5_qty,  products_price6_qty,  products_price7_qty,  products_price8_qty,  products_qty_blocks ) values ('{$tpg->customers_group_id}',  '{$tpg->customers_group_price}',  '$products_id',  '{$tpg->products_price1}',  '{$tpg->products_price2}',  '{$tpg->products_price3}',  '{$tpg->products_price4}',  '{$tpg->products_price5}',  '{$tpg->products_price6}',  '{$tpg->products_price7}',  '{$tpg->products_price8}',  '{$tpg->products_price1_qty}',  '{$tpg->products_price2_qty}',  '{$tpg->products_price3_qty}',  '{$tpg->products_price4_qty}',  '{$tpg->products_price5_qty}',  '{$tpg->products_price6_qty}',  '{$tpg->products_price7_qty}',  '{$tpg->products_price8_qty}',  '{$tpg->products_qty_blocks}' )");
            
}

$database->setQuery("Select products_extra_fields_id, products_extra_fields_value from #__osc_products_to_products_extra_fields where products_id='$key'");
$pefa = $database->loadObjectList();

foreach($pefa as $pef){
$database->setQuery("Insert into #__osc_products_to_products_extra_fields values('$products_id','{$pef->products_extra_fields_id}','{$pef->products_extra_fields_value}')");
$database->query();

}

}

}
//die();
$url = tep_href_link("prodman.php", 'msg=' . TEXT_UPDATE_COMPLETE);
  tep_redirect($url);


break;

case "Activate":
case "Deactivate":
$pid = $_REQUEST['pID'];
if($action == "Activate"){
 $flag = 1;
 }else{
 $flag = 0;
 }
foreach($pid as $prodid){
$database->setQuery("Update #__osc_products set products_status = '$flag' where products_id='$prodid'");
$database->query();
}
$url = tep_href_link("prodman.php", 'msg=' . TEXT_UPDATE_COMPLETE);
  tep_redirect($url);
  break;

case "Featured":
case "UnFeature":
//featured on/off
$pid = $_REQUEST['pID'];
if($action == "Featured"){
$flag = 1;
}else{
$flag = 0;
}
foreach($pid as $prodid){
$database->setQuery("Update #__osc_products set Featured_product = '$flag' where products_id='$prodid'");
$database->query();
}
$url = tep_href_link("prodman.php", 'msg=' . TEXT_UPDATE_COMPLETE);
  tep_redirect($url);
  break;


case "updateproduct":
case "insertproduct":

//ok first we need to set up the products table:
//so lets get its values:



$products_id = isset($_POST['pid'])?$_POST['pid']:'';

          $products_date_available = tep_db_prepare_input($_POST['products_date_available']);
          if($action == "insertproduct") $sql_addon_array['products_date_added'] = 'now()';
          if($action == "updateproduct") $sql_addon_array['products_last_modified'] = 'now()';

          $products_date_available = (date('Y-m-d') < $products_date_available) ? $products_date_available : 'null';
          // BOF Separate Pricing Per Customer, hide products and categories from groups
    $hide_from_these_groups = '@,';
             if ( $_POST['hide'] ) { // if any of the checkboxes are checked
		           foreach($_POST['hide'] as $val) {
		           $hide_from_these_groups .= tep_db_prepare_input($val).','; 
		           } // end foreach
	           }
    $hide_from_these_groups = substr($hide_from_these_groups,0,strlen($hide_from_these_groups)-1); // remove last comma
// EOF Separate Pricing Per Customer, hide products and categories from groups

          $sql_data_array = array('products_quantity' => (int)tep_db_prepare_input($_POST['products_quantity']),
                                  'products_model' => tep_db_prepare_input($_POST['products_model']),
                                  'Featured_product' => (int)tep_db_prepare_input($_POST['Featured_product']),
                                  'products_price' => tep_db_prepare_input($_POST['products_price']),	
                                  'products_date_available' => $products_date_available,
                                  'products_weight' => (float)tep_db_prepare_input($_POST['products_weight']),
                                  'products_status' => tep_db_prepare_input($_POST['products_status']),
                                  'products_tax_class_id' => tep_db_prepare_input($_POST['products_tax_class_id']),
                                  'manufacturers_id' => (int)tep_db_prepare_input($_POST['manufacturers_id']),
                                  'products_length' => tep_db_prepare_input($_POST['products_length']),
                                  'products_width' => tep_db_prepare_input($_POST['products_width']),
                                  'products_depth' => tep_db_prepare_input($_POST['products_depth']),
                                  'vendors_prod_id' => tep_db_prepare_input($_POST['vendors_prod_id']),
                                  'vendors_product_price' => tep_db_prepare_input($_POST['vendors_product_price']),
                                  'vendors_id' => tep_db_prepare_input($_POST['vendors_id']),
                                  'vendors_prod_comments' => tep_db_prepare_input($_POST['vendors_prod_comments']),
                                  'products_hide_from_groups' => $hide_from_these_groups,
                                  'supplier_id' => tep_db_prepare_input($_POST['vendors_id']),
                                  'suppliers_id' => tep_db_prepare_input($_POST['products_suppliers_id']),
                                  'affiliate_allow_product' => tep_db_prepare_input($_POST['affiliate_allow_product']),
                                  'products_price1' => tep_db_prepare_input($_POST['products_price1']),
                                  'products_price2' => tep_db_prepare_input($_POST['products_price2']),
                                  'products_price3' => tep_db_prepare_input($_POST['products_price3']),
                                  'products_price4' => tep_db_prepare_input($_POST['products_price4']),
                                  'products_price5' => tep_db_prepare_input($_POST['products_price5']),
                                  'products_price6' => tep_db_prepare_input($_POST['products_price6']),
                                  'products_price7' => tep_db_prepare_input($_POST['products_price7']),
                                  'products_price8' => tep_db_prepare_input($_POST['products_price8']),
                                  'products_price1_qty' => (($i=tep_db_prepare_input($_POST['products_price1_qty'])) < 0) ? 0 : $i,
                                  'products_price2_qty' => (($i=tep_db_prepare_input($_POST['products_price2_qty'])) < 0) ? 0 : $i,
                                  'products_price3_qty' => (($i=tep_db_prepare_input($_POST['products_price3_qty'])) < 0) ? 0 : $i,
                                  'products_price4_qty' => (($i=tep_db_prepare_input($_POST['products_price4_qty'])) < 0) ? 0 : $i,
                                  'products_price5_qty' => (($i=tep_db_prepare_input($_POST['products_price5_qty'])) < 0) ? 0 : $i,
                                  'products_price6_qty' => (($i=tep_db_prepare_input($_POST['products_price6_qty'])) < 0) ? 0 : $i,
                                  'products_price7_qty' => (($i=tep_db_prepare_input($_POST['products_price7_qty'])) < 0) ? 0 : $i,
                                  'products_price8_qty' => (($i=tep_db_prepare_input($_POST['products_price8_qty'])) < 0) ? 0 : $i,
                                  'products_qty_blocks' => (($i=tep_db_prepare_input($_POST['products_qty_blocks'])) < 1) ? 1 : $i
                                  );
       
       
       //uploads
        $products_image = new upload('products_image');
        $products_image->set_destination(DIR_FS_CATALOG_IMAGES);
        if ($products_image->parse() && $products_image->save()) {
          AddWatermark($products_image->filename);
        $sql_addon_array['products_image'] = tep_db_prepare_input($products_image->filename);
        }
        if($_POST['products_image'] == 'del'){
          $sql_addon_array['products_image'] = '';
        }
        
        $products_pdfupload = new upload('products_pdfupload');
        $products_pdfupload->set_destination(DIR_FS_CATALOG_IMAGES);
        if ($products_pdfupload->parse() && $products_pdfupload->save()) {
          $sql_addon_array['products_pdfupload'] = tep_db_prepare_input($products_pdfupload->filename);
        }
        
        $products_fileupload = new upload('products_fileupload');
        $products_fileupload->set_destination(DIR_FS_CATALOG_IMAGES);
        if ($products_fileupload->parse() && $products_fileupload->save()) {
          $sql_addon_array['products_fileupload'] = tep_db_prepare_input($products_fileupload->filename);
        }
        
        $products_mp3= new upload('products_mp3');
        $products_mp3->set_destination(DIR_FS_CATALOG_IMAGES);
        if ($products_mp3->parse() && $products_mp3->save()) {
          $sql_addon_array['products_mp3'] = tep_db_prepare_input($products_mp3->filename);
        }
        
        $products_vidupload = new upload('products_vidupload');
        $products_vidupload->set_destination(DIR_FS_CATALOG_IMAGES);
        if ($products_vidupload->parse() && $products_vidupload->save()) {
          $sql_addon_array['products_vidupload'] = tep_db_prepare_input($products_vidupload->filename);
        }

$sql_data_array = array_merge($sql_data_array, $sql_addon_array);
//ok lets populate / update
if ($action == "updateproduct"){
            tep_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
}else{
            tep_db_perform(TABLE_PRODUCTS, $sql_data_array);
            $products_id = tep_db_insert_id();
}
//osc_products complete, we also now have a products_id regardless!!!

//now lets update products_description:
$languages = tep_get_languages();
   for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
     $language_id = $languages[$i]['id'];

     $sql_data_array = array('products_name' => tep_db_prepare_input($_POST['products_name'][$language_id]),
                             'products_description' => tep_db_prepare_input($_POST['products_description'][$language_id]),
                             'products_url' => tep_db_prepare_input($_POST['products_url'][$language_id]));

            if ($action == 'insertproduct') {
              $insert_sql_data = array('products_id' => $products_id,
                                       'language_id' => $language_id);

              $sql_data_array = array_merge($sql_data_array, $insert_sql_data);

              tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
               } elseif ($action == 'updateproduct') {
              tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
}
}
//products_description complete:

//products_to_categories
$categories_id = $_POST['categories_id'];

if($action == 'insertproduct'){
$database->setQuery("Insert into #__osc_products_to_categories values($products_id,{$categories_id[0]})");
$database->query();
}else{
//delete and re-enter is the quickest + safest way to do this
$database->setQuery("Delete from #__osc_products_to_categories where products_id = '$products_id'");
$database->query();
echo $database->getErrorMsg();
foreach($categories_id as $catid){
$database->setQuery("Insert into #__osc_products_to_categories values($products_id,{$catid})");

echo "$products_id - $catid";
$database->query();
echo $database->getErrorMsg();
}
}


              $extra_fields_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " WHERE products_id = " . (int)$products_id);
          while ($products_extra_fields = tep_db_fetch_array($extra_fields_query)) {
            $extra_product_entry[$products_extra_fields['products_extra_fields_id']] = $products_extra_fields['products_extra_fields_value'];
          }

          if ($_POST['extra_field']) { // Check to see if there are any need to update extra fields.
            foreach ($_POST['extra_field'] as $key=>$val) {
            
              if (isset($extra_product_entry[$key])) { // an entry exists
                if ($val == '') tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " where products_id = " . (int)$products_id . " AND  products_extra_fields_id = " . $key);
                else tep_db_query("UPDATE " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " SET products_extra_fields_value = '" . tep_db_prepare_input($val) . "' WHERE products_id = " . (int)$products_id . " AND  products_extra_fields_id = " . $key);
              }
              else { // an entry does not exist
                if ($val != '') tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " (products_id, products_extra_fields_id, products_extra_fields_value) VALUES ('" . (int)$products_id . "', '" . $key . "', '" . tep_db_prepare_input($val) . "')");
              }
            }
          }
//end product_extra_fields


//sppc
 $customers_group_query = tep_db_query("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " where customers_group_id != '0' order by customers_group_id");
while ($customers_group = tep_db_fetch_array($customers_group_query)) // Gets all of the customers groups
  {
  $attributes_query = tep_db_query("select customers_group_id, customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where ((products_id = '" . $products_id . "') && (customers_group_id = " . $customers_group['customers_group_id'] . ")) order by customers_group_id");
  $attributes = tep_db_fetch_array($attributes_query);
  if (tep_db_num_rows($attributes_query) > 0) {
    if ($_POST['sppcoption'][$customers_group['customers_group_id']]) { // this is checking if the check box is checked
      if ($attributes['customers_group_id'] == $customers_group['customers_group_id'] ) {
	      $sppc_update_query = "set ";
	if (isset($_POST['sppcprice'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= "customers_group_price = '" . $_POST['sppcprice'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_qty_blocks'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_qty_blocks = '" . $_POST['sppcproducts_qty_blocks'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price1'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price1 = '" . $_POST['sppcproducts_price1'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price1_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price1_qty = '" . $_POST['sppcproducts_price1_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price2'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price2 = '" . $_POST['sppcproducts_price2'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price2_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price2_qty = '" . $_POST['sppcproducts_price2_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price3'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price3 = '" . $_POST['sppcproducts_price3'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price3_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price3_qty = '" . $_POST['sppcproducts_price3_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price4'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price4 = '" . $_POST['sppcproducts_price4'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price4_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price4_qty = '" . $_POST['sppcproducts_price4_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price5'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price5 = '" . $_POST['sppcproducts_price5'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price5_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price5_qty = '" . $_POST['sppcproducts_price5_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price6'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price6 = '" . $_POST['sppcproducts_price6'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price6_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price6_qty = '" . $_POST['sppcproducts_price6_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price7'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price7 = '" . $_POST['sppcproducts_price7'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price7_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price7_qty = '" . $_POST['sppcproducts_price7_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price8'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price8 = '" . $_POST['sppcproducts_price8'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price8_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price8_qty = '" . $_POST['sppcproducts_price8_qty'][$customers_group['customers_group_id']] . "' ";
	} // now we need to get rid of the last comma in the query string...
	   $sppc_update_query = rtrim($sppc_update_query);
	   $query_string_length = strlen($sppc_update_query);
	 if (substr($sppc_update_query, -1) == ",") {
		$sppc_update_query = substr($sppc_update_query, $query_string_length-1);
	 } 

	    tep_db_query("update " . TABLE_PRODUCTS_GROUPS . " " . $sppc_update_query . " where customers_group_id = '" . $attributes['customers_group_id'] . "' and products_id = '" . $products_id . "'");
     //   $attributes = tep_db_fetch_array($attributes_query);
      } 
  
    }  else { // checkbox is unchecked
      tep_db_query("delete from " . TABLE_PRODUCTS_GROUPS . " where customers_group_id = '" . $customers_group['customers_group_id'] . "' and products_id = '" . $products_id . "'");
      $attributes = tep_db_fetch_array($attributes_query);
    }
// next } : end if (tep_db_num_rows($attributes_query) > 0)
  } 
  elseif (($_POST['sppcoption'][$customers_group['customers_group_id']]) && ($_POST['sppcprice'][$customers_group['customers_group_id']] != '')) {
	      $sppc_insert_query = "set products_id = '" . $products_id . "', customers_group_id= '" . $customers_group['customers_group_id'] . "', ";
	if (isset($_POST['sppcprice'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= "customers_group_price = '" . $_POST['sppcprice'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_qty_blocks'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_qty_blocks = '" . $_POST['sppcproducts_qty_blocks'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price1'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price1 = '" . $_POST['sppcproducts_price1'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price1_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price1_qty = '" . $_POST['sppcproducts_price1_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price2'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price2 = '" . $_POST['sppcproducts_price2'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price2_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price2_qty = '" . $_POST['sppcproducts_price2_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price3'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price3 = '" . $_POST['sppcproducts_price3'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price3_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price3_qty = '" . $_POST['sppcproducts_price3_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price4'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price4 = '" . $_POST['sppcproducts_price4'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price4_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price4_qty = '" . $_POST['sppcproducts_price4_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price5'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price5 = '" . $_POST['sppcproducts_price5'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price5_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price5_qty = '" . $_POST['sppcproducts_price5_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price6'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price6 = '" . $_POST['sppcproducts_price6'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price6_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price6_qty = '" . $_POST['sppcproducts_price6_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price7'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price7 = '" . $_POST['sppcproducts_price7'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price7_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price7_qty = '" . $_POST['sppcproducts_price7_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price8'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price8 = '" . $_POST['sppcproducts_price8'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price8_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price8_qty = '" . $_POST['sppcproducts_price8_qty'][$customers_group['customers_group_id']] . "' ";
	} // now we need to get rid of the last comma in the query string...
	   $sppc_insert_query = rtrim($sppc_insert_query);
	   $query_string_length = strlen($sppc_insert_query);
	 if (substr($sppc_insert_query, -1) == ",") {
		$sppc_insert_query = substr($sppc_insert_query, $query_string_length-1);
	 } 

    tep_db_query("insert into " . TABLE_PRODUCTS_GROUPS . " " . $sppc_insert_query . "");
//    $attributes = tep_db_fetch_array($attributes_query);
  } // end elseif
} // end while ($customers_group = tep_db_fetch_array($customers_group_query))
  // EOF Separate Pricing Per Customer, Price Break 1.11.3 mod
//end sppc

//k now for subscriptoins::
if($_POST['pay_period'] !== ''){
$days_as_period = $_POST['pay_period'];
}else{
$days_as_period = $_POST['days_as_period'];
}
          $sql_data_array1 = array('price_period' => tep_db_prepare_input($_POST['price_period']),
                                   'oneday_price' => tep_db_prepare_input($_POST['oneday_price']),
                                   'days_as_period' => tep_db_prepare_input($days_as_period),
                                   'pay_period_type' => tep_db_prepare_input($_POST['pay_period_type']));

            $issubsquer = tep_db_query("Select count(*) as total from ".TABLE_SUBSCRIPTIONS." where productid = '". $products_id ." '");
            $issubs_check = tep_db_fetch_array($issubsquer);
            if ($issubs_check['total'] > 0) {
            tep_db_perform(TABLE_SUBSCRIPTIONS, $sql_data_array1, 'update', 'productid = \'' . tep_db_input($products_id) . '\'');}
            else
            {

            tep_db_query("INSERT INTO " . TABLE_SUBSCRIPTIONS . " (productid, pay_period_type, price_period, oneday_price, days_as_period, pay_dates) VALUES ( '$products_id', '" . $sql_data_array1['pay_period_type'] . "', '" . $sql_data_array1['price_period'] . "', '" . $sql_data_array1['oneday_price'] . "','" . $sql_data_array1['days_as_period'] . "', NULL)");
            }
//subscriptions completed::: dbl check time!

//auctions
/*
    [auctions_id] => 2
    [status] => 1
    [auctions_starting_price] => 5.0000
    [overbid_amount] => 1.00
    [expires_date] => 2008-08-31
    [expires_time] => 17:01:28
    [auctions_bids_id] => Array
        (
            [0] => 1
        )
 */
 //ok lets make sure we set it right:
 //first lets check if there is a record for the auction!!!
 //only if status == 1 though, if status == 0  we make sure to delete all acution info for this acution!!!
 //lets first format our timestring!!!
 $expires_date = $_POST['expires_date'] . ' ' . $_POST['expires_time'];
 $expires_date = DATE("Y-m-d H:i:s", strtotime($expires_date));
 
 if($_POST['status'] == 0 && $_POST['auctions_id'] > 0){
 //delete the auction
 $database->setQuery("Delete from #__osc_auctions where auctions_id = '{$_POST['auctions_id']}'");
 $database->query();
 $database->setQuery("Delete from #__osc_auctions_bids where auctions_id = '{$_POST['auctions_id']}'");
 $database->query();
 }elseif($_POST['status'] == 1){
  if($_POST['auctions_id'] > 0){
  //update the record
  $database->setQuery("Update #__osc_auctions set auctions_starting_price = '{$_POST['auctions_starting_price']}', overbid_amount = '{$_POST['overbid_amount']}', status='1', expires_date='$expires_date', auctions_last_modified = 'now()' where auctions_id='{$_POST['auctions_id']}'");
  }else{
  $database->setQuery("insert into #__osc_auctions(`products_id`, `auctions_starting_price`, `auctions_date_added`, `expires_date`, `status`, `overbid_amount`, `notified`) values('$products_id', '{$_POST['auctions_starting_price']}','now()','$expires_date','1','{$_POST['overbid_amount']}','0')");
  }
  $database->query();
  }
  
  if(isset($_POST['auctions_bids_id'])){
      $cids = implode(',', $_POST['auctions_bids_id']);
    $database->setQuery("DELETE FROM #__osc_auctions_bids WHERE auctions_bids_id IN ($cids)");
    $database->query();
    }
  
  
  
  
 $url = tep_href_link("prodman.php", 'msg=' . TEXT_UPDATE_COMPLETE);
  tep_redirect($url);
  break;
 

break;

case "setflag":
//active on/off
$pid = $_REQUEST['pID'];
$flag = $_REQUEST['flag'];
foreach($pid as $prodid){
$database->setQuery("Update #__osc_products set products_status = '$flag' where products_id='$prodid'");
$database->query();
}
$url = tep_href_link("prodman.php", 'msg=' . TEXT_UPDATE_COMPLETE);
  tep_redirect($url);
  break;

case "setfeat":
//featured on/off
$pid = $_REQUEST['pID'];
$flag = $_REQUEST['flag'];
foreach($pid as $prodid){
$database->setQuery("Update #__osc_products set Featured_product = '$flag' where products_id='$prodid'");
$database->query();
}
$url = tep_href_link("prodman.php", 'msg=' . TEXT_UPDATE_COMPLETE);
  tep_redirect($url);
  break;
}

$database->setQuery("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " order by customers_group_name");
$cgp = $database->loadObjectList();
$cgnarr = array();
foreach($cgp as $cgrp){
$cgnarr[$cgrp->customers_group_id] = $cgrp->customers_group_name;
}
?>
<div id="spiffycalendar" class="text"></div>
<link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_COMPONENT ?>includes/stylesheet.css">
<script language="javascript" src="<?php echo DIR_WS_COMPONENT ?>includes/general.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_COMPONENT ?>includes/javascript/spiffyCal/spiffyCal_v2_1.css">
<script language="JavaScript" src="<?php echo DIR_WS_COMPONENT ?>includes/javascript/spiffyCal/spiffyCal_v2_1.js"></script>
<script type="text/javascript" src="<?php echo DIR_WS_COMPONENT ?>includes/javascript/ajax.js"></script>
	<script type="text/javascript" src="<?php echo DIR_WS_COMPONENT ?>includes/javascript/tab-view.js"></script>
	



<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>

<?php echo tep_draw_form('adminForm', tep_href_link("prodman.php"), 'post', 'enctype="multipart/form-data"') . tep_draw_hidden_field("limitstart", "");
?>

<?php
switch($action){
//here we put the displayable options!!!!

case "Delete":

?>
<table class="adminlist">
 <tr>
   <td class="pageHeading">Delete Products</td>
 </tr>
 <tr>
   <td>Please confirm which categories you wish to delete the product from, should you select all categories, the product information itself will also be deleted.<strong>This Action is not Reversable</strong></td>
 </tr>
</table>

<?php
$pids = array();

foreach($_POST['pID'] as $prodid){
//ok here we need to be carefull...
//no use is us showing linked products 2ce or more.!!
if(!in_array($prodid, $pids)){
$pids[] = $prodid;
}

}

//ok we have weeded out the duplicates, now lets weed out the balance of the information!
foreach($pids as $prod){
$database->setQuery("Select p.products_id, pd.products_name, p2c.categories_id, c.*, s.*, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available from #__osc_products p left join #__osc_products_description pd on p.products_id=pd.products_id  left join #__osc_products_to_categories p2c on pd.products_id=p2c.products_id left join #__osc_subscriptions s on p.products_id = s.productid left join #__osc_categories_description c on c.categories_id = p2c.categories_id where pd.language_id = '" . (int) $languages_id . "' and p.products_id = '$prod'");
$res = $database->loadObjectList();
$r = 0;
foreach($res as $info){
if($r == 0) {
?>

<table class="adminlist" width="300"><thead>
 <tr>
   <th colspan="2"><?php echo $info->products_name;?></th>
 </tr>
</thead>
<?php
$r++;
}

?>
<tr><td width="5"><input type="checkbox" name="pid[]" value="<?php echo $info->products_id;?>,<?php echo $info->categories_id;?>"></td><td><?php echo $info->categories_name;?></td></tr>


<?php
}

echo '</table><hr>';
}



?><input type="submit" Value="Confirm"><input type="hidden" name="action" value="confirmdelete">
</form>
<?php
break;

case "Copy":
?>
<input type="hidden" name="action" value="copyconfirm">
<table class="adminlist">
 <tr>
   <td>Copy Products</td>
 </tr>
</table>
<table class="adminlist"><thead>
<tr>
 <th>Product Name</th>
 <th>Copy Type</th>
 <thDestination Category</th>
 <th></th>
</tr>
</thead>
<?php
$pids = $_POST['pID'];
foreach($pids as $pid){
$database->setQuery("Select products_name from #__osc_products_description where products_id='$pid'");
$pname = $database->loadResult();
?>
<tr>
 <td><?php echo $pname;?></td>
 <td><input type="radio" name="copy[<?php echo $pid;?>]" value="1" checked>Copy <input type="radio" name="copy[<?php echo $pid;?>]" value="2">Link</td>
 <td><?php echo tep_draw_pull_down_menu('categories_id['.$pid.']', tep_get_category_tree());?></td>
</tr>
<?php
}
?>
<tr><td colspan="2"><input type="submit" value="Confirm"></td></tr>
</table></form>
<?php

break;

case "edit":
case "Insert":
//this will handle both new and edit of current products
?>


 
<table class="adminlist">
 <tr>
   <td class="pageHeading">Add / Edit Products</td>
 </tr>
</table>
<?php
$languages = tep_get_languages();
//get all product information if it exists:
$pid = $_REQUEST['pID'];

if(isset($_REQUEST['pID'])){
//ok we are editing:
$database->setQuery("Select p.*, pd.*, p2c.categories_id, s.*, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available from #__osc_products p left join #__osc_products_description pd on p.products_id=pd.products_id  left join #__osc_products_to_categories p2c on pd.products_id=p2c.products_id left join #__osc_subscriptions s on p.products_id = s.productid where pd.language_id = '" . (int) $languages_id . "' and p.products_id = '{$pid[0]}'");
$result = $database->loadObjectList();
$thisprod = $result[0];
foreach($thisprod as $key=>$value){
$$key = $value;
}

//extra fields
$database->setQuery("SELECT * FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " WHERE products_id='{$pid[0]}'");
$pef_arr = $database->loadObjectList();
$pef = array();
foreach($pef_arr as $pef_row){
$pef[$pef_row->products_extra_fields_id] = $pef_row->products_extra_fields_value;
}

?>

<input type="hidden" name="action" value="updateproduct">
<input type="hidden" name="pid" value="<?php echo $products_id?>">
<?php
}else{
?>
<input type="hidden" name="action" value="insertproduct">
<?php
}
 if (!isset($products_status)) $products_status = '1';
    switch ($products_status) {
      case '0': $in_status = false; $out_status = true; break;
      case '1':
      default: $in_status = true; $out_status = false;
    }
 if (!isset($affiliate_allow_product)) $affiliate_allow_product = '1';
    switch ($affiliate_allow_product) {
      case '0': $in_status2 = false; $out_status2 = true; break;
      case '1':
      default: $in_status2 = true; $out_status2 = false;
    }
 if (!isset($Featured_product)) $Featured_product = '0';
    switch ($Featured_product) {
      case '0': $in_status3 = false; $out_status3 = true; break;
      case '1':
      default: $in_status3 = true; $out_status3 = false;
    }
    
$tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
    $tax_class_query = tep_db_query("select tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
    while ($tax_class = tep_db_fetch_array($tax_class_query)) {
      $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
                                 'text' => $tax_class['tax_class_title']);
    }
    
$manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE));
    $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
    while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
      $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
                                     'text' => $manufacturers['manufacturers_name']);
    }
    
$vendors_array = array(array('id' => '1', 'text' => 'NONE'));
    $vendors_query = tep_db_query("select vendors_id, vendors_name from " . 

TABLE_VENDORS . " order by vendors_name");
    while ($vendors = tep_db_fetch_array($vendors_query)) {
      $vendors_array[] = array('id' => $vendors['vendors_id'],
                                     'text' => $vendors['vendors_name']);
    }
    
$supplier_array = array(array('id' => 0, 'text' => TEXT_NONE));
$supplier_query = tep_db_query("select suppliers_id, suppliers_name from " . TABLE_SUPPLIERS . " order by suppliers_name");

            while ( $supplier_result = tep_db_fetch_array($supplier_query) ){

                        $supplier_array[] = array('id' => $supplier_result['suppliers_id'],
                                                'text' => $supplier_result['suppliers_name']);

            }
?>
<script language="javascript">
   var cal1=new ctlSpiffyCalendarBox("cal1", "adminForm", "products_date_available","btnDate1","<?php echo $products_date_available;?>",scBTNMODE_CUSTOMBLUE);
</script>
<script language="javascript"><!--
var tax_rates = new Array();
<?php
    for ($i=0, $n=sizeof($tax_class_array); $i<$n; $i++) {
      if ($tax_class_array[$i]['id'] > 0) {
        echo 'tax_rates["' . $tax_class_array[$i]['id'] . '"] = ' . tep_get_tax_rate_value($tax_class_array[$i]['id']) . ';' . "\n";
      }
    }
?>

function doRound(x, places) {
  return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
}

function getTaxRate() {
  var selected_value = document.forms["adminForm"].products_tax_class_id.selectedIndex;
  var parameterVal = document.forms["adminForm"].products_tax_class_id[selected_value].value;

  if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) {
    return tax_rates[parameterVal];
  } else {
    return 0;
  }
}

function updateGross() {
  var taxRate = getTaxRate();
  var grossValue = document.forms["adminForm"].products_price.value;

  if (taxRate > 0) {
    grossValue = grossValue * ((taxRate / 100) + 1);
  }

  document.forms["adminForm"].products_price_gross.value = doRound(grossValue, 4);
}

function updateNet() {
  var taxRate = getTaxRate();
  var netValue = document.forms["adminForm"].products_price_gross.value;

  if (taxRate > 0) {
    netValue = netValue / ((taxRate / 100) + 1);
  }

  document.forms["adminForm"].products_price.value = doRound(netValue, 4);
}
//--></script>

<div id="dhtmlgoodies_tabView1">
	<div class="dhtmlgoodies_aTab">
	<?php
	//here the standard settings
	?>
	<table width="100%" class="adminlist">
	<tr>
    <td><?php echo TEXT_PRODUCTS_STATUS; ?></td>
    <td><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('products_status', '1', $in_status) . '&nbsp;' . TEXT_PRODUCT_AVAILABLE . '&nbsp;' . tep_draw_radio_field('products_status', '0', $out_status) . '&nbsp;' . TEXT_PRODUCT_NOT_AVAILABLE; ?></td>
  </tr>
	<tr>
    <td><?php echo TEXT_PRODUCTS_AFFILIATE; ?></td>
    <td><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('affiliate_allow_product', '1', $in_status2) . '&nbsp;' . TEXT_PRODUCT_AFFILIATE . '&nbsp;' . tep_draw_radio_field('affiliate_allow_product', '0', $out_status2) . '&nbsp;' . TEXT_PRODUCT_NOT_AFFILIATE; ?></td>
  </tr>
  <tr>
    <td><?php echo TEXT_Featured_Product;?></td>
    <td><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('Featured_product', '1', $in_status3) . '&nbsp;' . TEXT_PRODUCT_AFFILIATE . '&nbsp;' . tep_draw_radio_field('Featured_product', '0', $out_status3) . '&nbsp;' . TEXT_PRODUCT_NOT_AFFILIATE; ?></td>
  </tr>
	
  <?php
  //if the product is linked to more than one category, we need this modification, so 
  //if new product we show the singular only
  if(isset($_REQUEST['pID'])){
  //exists, lets pull all the categories out
  $database->setQuery("Select categories_id from #__osc_products_to_categories where products_id='{$pid[0]}'");
  $crows = $database->loadObjectList();
  $ccrcnt = 0;
  foreach ($crows as $crow){
  if($ccrcnt == 0){
  ?>
    <tr>
    <td><?php echo TEXT_PRODUCT_CATEGORY;?></td>
    <?php
  }else{
    ?>
    <tr>
    <td><?php echo TEXT_PRODUCT_CATEGORY;?></td>
    <?php
  }
  ?>
    
   <td><?php echo tep_draw_pull_down_menu('categories_id[]', tep_get_category_tree(), $crow->categories_id);?></td>
  </tr>
  <?php
  $ccrcnt++;
  }
  
  }else{
  
  ?>
  <tr>
    <td><?php echo TEXT_PRODUCT_CATEGORY;?></td>
    <td><?php echo tep_draw_pull_down_menu('categories_id[]', tep_get_category_tree(), $categories_id);?></td>
  </tr>
  <?php
  }
  ?>
  
  <tr>
            <td ><?php echo TEXT_PRODUCTS_MANUFACTURER; ?></td>
            <td ><?php echo tep_draw_pull_down_menu('manufacturers_id', $manufacturers_array, $manufacturers_id); ?></td>
          </tr>
	<tr>
    <td><?php echo TEXT_PRODUCTS_DATE_AVAILABLE;?></td>
    <td><SCRIPT language="JavaScript">cal1.writeControl(); cal1.dateFormat="yyyy-MM-dd";</SCRIPT></td>
  </tr>
  <tr>
            <td ><?php echo TEXT_PRODUCTS_QUANTITY; ?></td>
            <td ><?php echo tep_draw_input_field('products_quantity', $products_quantity, 'size="4"'); ?></td>
</tr>
   <tr>
            <td ><?php echo TEXT_PRODUCTS_MODEL; ?></td>
            <td ><?php echo  tep_draw_input_field('products_model', $products_model, 'size="10"'); ?></td>
          </tr>
  <tr> 
  <?php
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
?>
          <tr>
            <td ><?php echo TEXT_PRODUCTS_NAME; ?></td>
            <td ><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('products_name[' . $languages[$i]['id'] . ']', tep_get_products_name($products_id, $languages[$i]['id'])); ?></td>
          </tr>
<?php
    }
?>
</tr>
<tr>
<?php
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
?>
          <tr>
            <td valign="top"><?php  echo TEXT_PRODUCTS_DESCRIPTION; ?></td>
            <td><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              
                <td  valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
                <td >
              <?php
					// parameters : areaname, content, hidden field, width, height, rows, cols
					editorArea( 'products_description[' . $languages[$i]['id'] . ']',  tep_get_products_description($products_id, $languages[$i]['id']) , 'products_description[' . $languages[$i]['id'] . ']', '100%;', '300', '60', '20' ) ; ?></td></tr>
            </table></td>
          </tr>
<?php
    }
?>

	</table>
	</div>
	
	<div class="dhtmlgoodies_aTab">
	<table class="adminlist">
	<tr bgcolor="#ebebff">
            <td ><?php echo TEXT_PRODUCTS_TAX_CLASS; ?></td>
            <td ><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_pull_down_menu('products_tax_class_id', $tax_class_array, $products_tax_class_id, 'onchange="updateGross()"'); ?></td>
          </tr>
          <tr bgcolor="#ebebff">
            <td ><?php echo TEXT_PRODUCTS_PRICE_NET; ?></td>
            <td ><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price', $products_price, 'onKeyUp="updateGross()"'); ?></td>
          </tr>
          <tr bgcolor="#ebebff">
            <td ><?php echo TEXT_PRODUCTS_PRICE_GROSS; ?></td>
            <td ><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price_gross', $products_price, 'OnKeyUp="updateNet()"'); ?></td>
          </tr>
          <script>updateGross();</script>
          
            <tr>
            <td colspan="2" ><?php echo TEXT_HIDE_PRODUCTS_FROM_GROUP; ?></td>
          </tr>
          
          
<?php   
   $hide_customers_group_query = tep_db_query("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " order by customers_group_id");
   $hide_from_groups_array = explode(',',$products_hide_from_groups);
   $hide_from_groups_array = array_slice($hide_from_groups_array, 1); // remove "@" from the array
   while ($hide_customers_group = tep_db_fetch_array($hide_customers_group_query)) {
?>
      <tr>
       <td  colspan="2"><?php 
      if (isset($hide)) {
	   echo tep_draw_checkbox_field('hide[' . $hide_customers_group['customers_group_id'] . ']',  $hide_customers_group['customers_group_id'] , (isset($hide[ $hide_customers_group['customers_group_id']])) ? 1: 0);
      } else {
      echo tep_draw_checkbox_field('hide[' . $hide_customers_group['customers_group_id'] . ']',  $hide_customers_group['customers_group_id'] , (in_array($hide_customers_group['customers_group_id'], $hide_from_groups_array)) ? 1: 0);
      } ?>&#160;&#160;<?php echo $hide_customers_group['customers_group_name']; ?></td>
      </tr>
<?php
        } // end while ($hide_customers_group = tep_db_fetch_array($hide_customers_group_query))
?>


          
            <tr>
              <td colspan="2"><table class="adminlist"><thead><tr>
              <?php 
              
              $database->setQuery("select customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " where customers_group_id = '0'");
$name_retail = $database->loadResult();
?>
              <th align="left" colspan="3"><?php echo TEXT_PRICE_BREAK;?> - <?php echo $name_retail;?></th>
          </tr>
          </thead>
        <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_QTY_BLOCKS; ?></td>
            <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_qty_blocks', $products_qty_blocks, 'size="10"') . '&nbsp;' . TEXT_PRODUCTS_QTY_BLOCKS_INFO ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE1; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price1', $products_price1, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE1_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price1_qty', $products_price1_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE2; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price2', $products_price2, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE2_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price2_qty', $products_price2_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE3; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price3', $products_price3, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE3_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price3_qty', $products_price3_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE4; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price4', $products_price4, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE4_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price4_qty', $products_price4_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE5; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price5', $products_price5, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE5_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price5_qty', $products_price5_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE6; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price6', $products_price6, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE6_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price6_qty', $products_price6_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE7; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price7', $products_price7, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE7_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price7_qty', $products_price7_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE8; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price8', $products_price8, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE8_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price8_qty', $products_price8_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          </table>
          </td>
        </tr>
          <?php
    $customers_group_query = tep_db_query("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " where customers_group_id != '0' order by customers_group_id");
    $header = false;
    while ($customers_group = tep_db_fetch_array($customers_group_query)) {
	    
     if (tep_db_num_rows($customers_group_query) > 0) {
       $attributes_query = tep_db_query("select customers_group_id, customers_group_price, products_price1, products_price2, products_price3, products_price4, products_price5, products_price6, products_price7, products_price8, products_price1_qty, products_price2_qty, products_price3_qty, products_price4_qty, products_price5_qty, products_price6_qty, products_price7_qty, products_price8_qty, products_qty_blocks from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . $products_id . "' and customers_group_id = '" . $customers_group['customers_group_id'] . "' order by customers_group_id");
     } else {
         $attributes = array('customers_group_id' => 'new');
     }
 if (!$header) { ?>

    <tr>
    <td colspan="2" style="font-style: italic">Note that if the price field for the customer group is left empty, <b>no</b> price and <b>no</b> price break levels and quantities for that customer group will be inserted in the database.<br />
If a field or fields is/are filled, but the checkbox is unchecked no price/price break levels etc. will be inserted either.<br />
If a price and price break levels are already inserted in the database, but the checkbox unchecked they will be removed from the database.
</td>
    </tr>
 <?php 
 $header = true; 
 } // end if (!header), makes sure this is only shown once   
 ?>
 <tr><td colspan="2">
 <table width="100%"><thead>
   <tr>
    <th><?php echo TEXT_PRICE_BREAK;?> - <?php echo $customers_group['customers_group_name'] ?> </th>
    </tr>
    </thead>
    <tr><td>

<table>
        <tr bgcolor="#ebebff">
       <td class="main"><?php 
             if (isset($sppcoption)) {
	   echo tep_draw_checkbox_field('sppcoption[' . $customers_group['customers_group_id'] . ']', 'sppcoption[' . $customers_group['customers_group_id'] . ']', (isset($sppcoption[ $customers_group['customers_group_id']])) ? 1: 0);
      } else {
      echo tep_draw_checkbox_field('sppcoption[' . $customers_group['customers_group_id'] . ']', 'sppcoption[' . $customers_group['customers_group_id'] . ']', true) . '&nbsp;' . $customers_group['customers_group_name'];
      }
      ?>
 &nbsp;</td>
       <td class="main"><?php
       $customer_prices_set = false;
       $customer_prices_in_post = false;
       if ($attributes = tep_db_fetch_array($attributes_query)) { 
	       $customer_prices_set = true;
       echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcprice[' . $customers_group['customers_group_id'] . ']', $attributes['customers_group_price']); 
       }  else {
	       if (isset($sppcprice[$customers_group['customers_group_id']])) { // when a preview was done and the back button used
		       $customer_prices_in_post = true;
		       $sppc_cg_price = $sppcprice[$customers_group['customers_group_id']];
	       } else { // nothing in the db, nothing in the post variables
		       $sppc_cg_price = '';
	       }
	   echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcprice[' . $customers_group['customers_group_id'] . ']', $sppc_cg_price );
	 }  ?></td>
    </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_QTY_BLOCKS; ?></td>
            <td class="main"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_qty_blocks = $attributes['products_qty_blocks'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_qty_blocks = $sppcproducts_qty_blocks[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_qty_blocks = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_qty_blocks[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_qty_blocks, 'size="10"') . '&nbsp;' . TEXT_PRODUCTS_QTY_BLOCKS_INFO;
 ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE1; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price1 = $attributes['products_price1'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price1 = $sppcproducts_price1[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price1 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price1[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price1, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE1_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price1_qty = $attributes['products_price1_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price1_qty = $sppcproducts_price1_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price1_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price1_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price1_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE2; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price2 = $attributes['products_price2'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price2 = $sppcproducts_price2[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price2 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price2[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price2, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE2_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price2_qty = $attributes['products_price2_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price2_qty = $sppcproducts_price2_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price2_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price2_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price2_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE3; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price3 = $attributes['products_price3'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price3 = $sppcproducts_price3[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price3 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price3[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price3, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE3_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price3_qty = $attributes['products_price3_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price3_qty = $sppcproducts_price3_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price3_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price3_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price3_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE4; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price4 = $attributes['products_price4'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price4 = $sppcproducts_price4[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price4 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price4[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price4, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE4_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price4_qty = $attributes['products_price4_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price4_qty = $sppcproducts_price4_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price4_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price4_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price4_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE5; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price5 = $attributes['products_price5'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price5 = $sppcproducts_price5[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price5 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price5[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price5, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE5_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price5_qty = $attributes['products_price5_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price5_qty = $sppcproducts_price5_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price5_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price5_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price5_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE6; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price6 = $attributes['products_price6'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price6 = $sppcproducts_price6[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price6 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price6[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price6, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE6_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price6_qty = $attributes['products_price6_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price6_qty = $sppcproducts_price6_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price6_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price6_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price6_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE7; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price7 = $attributes['products_price7'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price7 = $sppcproducts_price7[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price7 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price7[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price7, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE7_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price7_qty = $attributes['products_price7_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price7_qty = $sppcproducts_price7_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price7_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price7_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price7_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE8; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price8 = $attributes['products_price8'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price8 = $sppcproducts_price8[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price8 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price8[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price8, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE8_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price8_qty = $attributes['products_price8_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price8_qty = $sppcproducts_price8_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price8_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price8_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price8_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          </table>
       
          </td></tr>
          </table>
        </td></tr>
<?php
        } // end while ($customers_group = tep_db_fetch_array($customers_group_query))
?>
        
        
          </table>
	
	</div>
	
		<div class="dhtmlgoodies_aTab">
	<table width="100%" class="adminlist">
	 <tr>
    <td><?php echo TEXT_PRODUCTS_IMAGE;?></td>
    <td><input type="file" name="products_image"><br><?php echo "($products_image)";?></td>
   </tr>
   <tr>
    <td><?php echo TEXT_PRODUCTS_PDFUPLOAD; ?></td>
    <td><input type="file" name="products_pdfupload"><br><?php echo "($products_pdfupload)";?></td>
   </tr>
   <tr>
    <td><?php echo TEXT_PRODUCTS_VIDUPLOAD; ?></td>
    <td><input type="file" name="products_vidupload"><br><?php echo "($products_vidupload)";?></td>
   </tr>
   <tr>
    <td><?php echo TEXT_PRODUCTS_MP3UPLOAD; ?></td>
    <td><input type="file" name="products_mp3"><br><?php echo "($products_mp3)";?></td>
   </tr>
   <tr>
    <td><?php echo TEXT_PRODUCTS_FILEUPLOAD; ?></td>
    <td><input type="file" name="products_fileupload"><br><?php echo "($products_fileupload)";?></td>
   </tr>
  </table>
   
   
	</div>
	

	
	<div class="dhtmlgoodies_aTab">
	<table class="adminlist">
	<?php
	//normal weight url etc!
	?>
	<?php
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
?>
          <tr>
            <td ><?php if ($i == 0) echo TEXT_PRODUCTS_URL . '<br><small>' . TEXT_PRODUCTS_URL_WITHOUT_HTTP . '</small>'; ?></td>
            <td ><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('products_url[' . $languages[$i]['id'] . ']', tep_get_products_url($products_id, $languages[$i]['id'])); ?></td>
          </tr>
<?php
    }
?>
	  <tr>
            <td ><?php echo TEXT_PRODUCTS_WEIGHT; ?></td>
            
            <td ><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_weight', $products_weight); ?></td>
          </tr>
          <tr>
            <td ><?php echo TEXT_PRODUCTS_LENGTH; ?></td>
            <td ><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_length', $products_length); ?></td>
          </tr>
						<tr>
            <td ><?php echo TEXT_PRODUCTS_WIDTH; ?></td>
            <td ><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_width', $products_width); ?></td>
          </tr>
						<tr>
            <td ><?php echo TEXT_PRODUCTS_DEPTH; ?></td>
            <td ><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_depth', $products_depth); ?></td>
          </tr>
<?php
// START: Extra Fields Contribution (chapter 1.4)
      // Sort language by ID  
	  for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
	    $languages_array[$languages[$i]['id']]=$languages[$i];
	  }
      $extra_fields_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_EXTRA_FIELDS . " ORDER BY products_extra_fields_order");
      while ($extra_fields = tep_db_fetch_array($extra_fields_query)) {
	  // Display language icon or blank space
        if ($extra_fields['languages_id']==0) {
	      $m=tep_draw_separator('pixel_trans.gif', '24', '15');
	    } else $m= tep_image(DIR_WS_CATALOG_LANGUAGES . $languages_array[$extra_fields['languages_id']]['directory'] . '/images/' . $languages_array[$extra_fields['languages_id']]['image'], $languages_array[$extra_fields['languages_id']]['name']);
?>
          <tr>
            <td ><?php echo $extra_fields['products_extra_fields_name']; ?>:</td>
            <td ><?php echo $m . '&nbsp;' . tep_draw_input_field("extra_field[".$extra_fields['products_extra_fields_id']."]", $pef[$extra_fields['products_extra_fields_id']]); ?></td>
          </tr>
<?php
}
// END: Extra Fields Contribution
?>
</table>
	</div>
	
	
			<div class="dhtmlgoodies_aTab">
			<table class="adminlist">
			<tr>
        <td ><?php echo TEXT_SUPPLIER; ?></td>
        <td ><?php echo  tep_draw_pull_down_menu('products_suppliers_id', $supplier_array, $suppliers_id);?></td>
      </tr>
      <tr>
            <td ><?php echo TEXT_PRODUCTS_VENDORS; ?></td>
            <td ><?php echo  tep_draw_pull_down_menu('vendors_id', $vendors_array, $vendors_id); ?></td>
     </tr>
     <tr>
            <td ><?php echo TEXT_VENDORS_PROD_ID; ?></td>
            <td ><?php echo tep_draw_input_field('vendors_prod_id', $vendors_prod_id); ?></td>
          </tr>
     <tr >
          <td ><?php echo TEXT_VENDORS_PRODUCT_PRICE_BASE; 

?></td>
            <td ><?php echo tep_draw_input_field('vendors_product_price', $vendors_product_price, 'onKeyUp="updateNet()"'); ?></td>
          </tr>
          <tr>
             <td ><?php echo TEXT_VENDORS_PROD_COMMENTS; ?></td>
                <td ><?php echo tep_draw_textarea_field('vendors_prod_comments', 'soft', '70', '5',tep_get_vendors_prod_comments($products_id)); ?></td>
              </tr>
          
          
        </table>  
	</div>
	
	<div class="dhtmlgoodies_aTab">
	<?php
	if(show("newsubs")){
	$p = "By Period";
 $subscription_pay_period_type1 = array(array('id' => 'Annually', 'text' => Annually));
    $subscription_pay_period_type1[] = array('id' => 'Quarterly','text' => Quarterly);
    $subscription_pay_period_type1[] = array('id' => 'Monthly','text' => Monthly);
    $subscription_pay_period_type1[] = array('id' => 'Weekly','text' => Weekly);
    $subscription_pay_period_type1[] = array('id' => "$p",'text' => "$p");


$paramss = 'onchange="if (this.selectedIndex == 4) { this.form.pay_period.disabled = false; this.form.pay_period.focus(); }else{ this.form.pay_period.disabled = true; }"'; ?>

<table cellSpacing="0" cellPadding="2" width="514" border="0" class="adminlist">

  <tr>
    <td  width="516">
    <table cellSpacing="0" cellPadding="10" width="516" border="0" class="adminlist">
      <tr>
        <td width="496">
        <table cellPadding="0" border="0" class="adminlist">
                     <tr>
              <td class="main">Pay period</td>
              <td class="main">Period fee ($)</td>
              <td class="main">Cost of one day ($)</td>
              <td class="main">Days same period</td>
            </tr>
            <tr>
              <td vAlign="top">
              <?php echo  tep_draw_separator('pixel_trans.gif', '12', '15') . tep_draw_pull_down_menu('pay_period_type', $subscription_pay_period_type1, $pay_period_type, $paramss); ?></td>
              <td vAlign="top">
              <?php echo  tep_draw_input_field('price_period', $price_period); ?></td>
              <td vAlign="top">
              <?php echo  tep_draw_input_field('oneday_price', $oneday_price); ?></td>
              <td vAlign="top">
              <?php echo  tep_draw_input_field('days_as_period', $days_as_period); ?></td>
             </tr>
            <tr>
              <td colSpan="4" valign=top>
              <?php echo tep_draw_separator('pixel_trans.gif', '12', '15'); ?><input disabled size="12" name="pay_period" value=<?php echo $pay_period ?>>&nbsp;days</td>
            </tr>
                           </table>
        </td>
      </tr>
    </table>
    </td>
  </tr>
</table>
</a>
	</div>
	<?php
	}
	?>
<div class="dhtmlgoodies_aTab">
<table class="adminlist">
  <tr>
    <td>
    <?php
    if(isset($_REQUEST['pID'])){
    $database->setQuery("Select * from #__osc_auctions where products_id = '{$pid[0]}' order by auctions_id desc");
    $aucrows = $database->loadObjectList();

    if($aucrows){
    $auc = $aucrows[0];
    foreach($auc as $key=>$value){
    $$key = $value;
    }
    $expires_time = date("H:i:s", strtotime("$expires_date"));
    $expires_date = date("Y-m-d",strtotime("$expires_date"));

    }
    }
    
    
    
    if (!isset($status)) $status = '0';
    switch ($status) {
      case '0': $in_statusa = false; $out_statusa = true; break;
      case '1':
      default: $in_statusa = true; $out_statusa = false;
    }
    ?>
    <input type="hidden" name="auctions_id" value="<?php echo $auctions_id;?>">
    Auction Product </td><td><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('status', '1', $in_statusa) . '&nbsp;' . TEXT_PRODUCT_AFFILIATE . '&nbsp;' . tep_draw_radio_field('status', '0', $out_statusa) . '&nbsp;' . TEXT_PRODUCT_NOT_AFFILIATE; ?><br><strong> Setting to no will delete all auction references for an auction, the auction will need to be restarted again!!!</strong></td></tr>
    
    <tr><td>Auctions Starting Price </td><td><input type="text" name="auctions_starting_price" value="<?php echo $auctions_starting_price;?>"></td></tr>
    <tr><td>Overbid Amount </td><td><input type="text" name="overbid_amount" value="<?php echo $overbid_amount;?>"></td></tr>
    <script language="javascript">
   var cal2=new ctlSpiffyCalendarBox("cal2", "adminForm", "expires_date","btnDate2","<?php echo $expires_date;?>",scBTNMODE_CUSTOMBLUE);
</script>
    <tr>
    <td>Auction End Date:</td><td><SCRIPT language="JavaScript">cal2.writeControl(); cal2.dateFormat="yyyy-MM-dd";</SCRIPT></td></tr>
    <tr>
      <td>
    Auction End Time</td><td><input type="text" name="expires_time" value="<?php echo $expires_time;?>"> (HH:MM:SS eg 18:30:00)</td></tr>
    <tr><td colspan="2"><b>Auction Notes:</b><ul><li>You can enter a percentage to deduct in the Auctions Price field, for example: <b>20%</b></li><li>If you enter a new price, the decimal separator must be a '.' (decimal-point), example: <b>49.99</b></li><li>Leave the expiry date empty for no expiration</li><li>Setting an active auction to inactive will delete all information regarding the auction including bids!!!</li></ul></td></tr>
    
    </table>
    <?php
    if($auctions_id){
    $database->setQuery("Select a.auctions_bids_id, a.bid_price, a.bid_status, a.bid_date_added, c.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address from #__osc_auctions_bids a left join #__osc_customers c on a.customers_id=c.customers_id where a.auctions_id = '$auctions_id' order by a.auctions_bids_id desc");
    $bids_ar = $database->loadObjectList();
    echo $database->getErrorMsg();
    ?>
    <table class="adminlist">
     <thead>
      <tr>
        <th width="4">Del</th>
        <th>Customer No</th>
        <th>Customer Name</th>
        <th>Customer Email</th>
        <th>Bid Price</th>
        <th>Bid Status</th>
        <th>Bid Placed</th>
       </tr>
      </thead>
      <?php
      if($bids_ar){
      foreach ($bids_ar as $bid){
      ?>
      <tr>
        <td><input type="checkbox" name="auctions_bids_id[]" value="<?php echo $bid->auctions_bids_id;?>"></td>
        <td><?php echo $bid->customers_id;?></td>
        <td><?php echo $bid->customers_firstname . ' ' . $bid->customers_lastname;?></td>
        <td><?php echo $bid->customers_email_address;?></td>
        <td><?php echo $bid->bid_price;?></td>
        <td><?php echo $bid->bid_status;?></td>
        <td><?php echo $bid->bid_date_added;?></td>
      </tr>
      <?php
      }
      }
      ?>
      </table>
    <?php
    }
    ?>
    
    
</div>

</div>

<script type="text/javascript">
initTabs('dhtmlgoodies_tabView1',Array(' General ', ' Pricing ', ' Images / Files ',' Product Fields ' , ' Vendors / Suppliers ' , ' Subscription Settings ' , ' Auction Settings ' ),0,'100%','',Array(false,false,false, false, false, false));
</script>

<table class="adminlist">
 <tr>
  <td align="right">
   <?php echo tep_image_submit('button_save.gif', IMAGE_SAVE) . ' <a href="' . tep_href_link("prodman.php") . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
   ?>
   </td>
  </tr>
</table>

<?php
break;
default:

//ok lets pull out the products
$database->setQuery("Select p.*, pd.*, cd.*, v.vendors_name from #__osc_products p left join #__osc_products_description pd on p.products_id=pd.products_id  left join #__osc_products_to_categories p2c on pd.products_id=p2c.products_id left join #__osc_categories_description cd on p2c.categories_id = cd.categories_id left join #__osc_vendors v on p.vendors_id = v.vendors_id where pd.language_id = '" . (int) $languages_id . "' and cd.language_id = '" . (int)$languages_id . "' order by pd.products_name asc");
$result = $database->loadObjectList();
$total = count($result);

    require_once ($GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php');
    $limit = $mainframe->getUserStateFromRequest("viewlistlimit", 'limit',25);
    $limitstart = $mainframe->getUserStateFromRequest("view{$option}limitstart", 'limitstart', 0);
    
    $pageNav = new mosPageNav($total, $limitstart, $limit);
    $rows = array_slice($result, $pageNav->limitstart, $pageNav->limit);

?>

<table class="adminlist">
 <tr>
   <td class="pageHeading">Products</td>
   <td align="right" nowrap>Display: <?php echo $pageNav->writeLimitBox(); ?></td>
 </tr>
</table>
<table class="adminlist"><thead>
<tr>
  <th width="5">Pid</th>
  <th width="5"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows) + 1;?>);" /></th>
  <th width = "10">Products Model</th>
  <th width = "*">Products Name</th>
  <th width = "100">Category</th>
  <th width = "50">Products Price</th>
  <th width = "4">Products QTY</th>
  <th width = "4">Active</th>
  <th width = "4">Featured</th>
  <th width = "100">Vendor</th>
  <th width = "100">Hidden</th>
</th>
</thead>
<?php
//ok now for the magic
$disp = 0;
$cnt = 1; 
foreach($rows as $row){
?>
<tr class="dataTableRow<?php echo $disp;?>" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">
  <td><?php echo $row->products_id;?></td>
  <td><input type="checkbox" id='cb<?php echo $cnt;?>' name="pID[]" value="<?php echo $row->products_id;?>"></td>
  <td><?php echo $row->products_model;?></td>
  <td><a href="<?php echo tep_href_link("prodman.php" , "action=edit&pID[]=" . $row->products_id);?>"><?php echo $row->products_name;?></a></td>
  <td><a href="<?php echo tep_href_link("catprodnew.php" , "action=edit&cid[]=" . $row->categories_id);?>"><?php echo $row->categories_name;?></a></td>
  <td><?php echo $currencies->format($row->products_price);?></td>
  <td><?php echo $row->products_quantity;?></td>
  <td><?php if ($row->products_status == '1') {
        echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . '&nbsp;&nbsp;<a href="' . tep_href_link("prodman.php", 'action=setflag&flag=0&pID[]=' . $row->products_id) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>';
      } else {
        echo '<a href="' . tep_href_link("prodman.php", 'action=setflag&flag=1&pID[]=' . $row->products_id) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10);
      }
      ;?></td>
<td><?php if ($row->Featured_product == '1') {
        echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . '&nbsp;&nbsp;<a href="' . tep_href_link("prodman.php", 'action=setfeat&flag=0&pID[]=' . $row->products_id) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>';
      } else {
        echo '<a href="' . tep_href_link("prodman.php", 'action=setfeat&flag=1&pID[]=' . $row->products_id) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10);
      }
      ;?></td>      
<td><?php echo $row->vendors_name;?></td>
<td><?php
$hidarr = explode(",", $row->products_hide_from_groups);
if(count($hidarr > 1)){
unset($hidarr[0]);
foreach($hidarr as $group){
echo "<li>" . $cgnarr[$group] . "</li>";
}
}
?></td>

</tr>
<?php
$cnt++;
$disp = 1 - $disp;
}
?>
<tr><th align = "center" colspan = "11"><center><?php echo $pageNav->writePagesLinks(); ?> </center>
                            </th>
                        </tr>

                        <tr>
                            <td align = "center" colspan = "11"> <center><?php echo $pageNav->writePagesCounter(); ?>
                            </td>
                        </tr>
                        <tr>
 <tr>
 <td colspan="11" align="right">
 <input type="submit" value="Activate" name="action"> <input type="submit" value="Deactivate" name="action"> 
 <input type="submit" value="Featured" name="action"> <input type="submit" value="UnFeature" name="action"> 
 <input type="submit" value="Delete" name="action"> <input type="submit" value="Insert" name="action"> 
 <input type="submit" value="Copy" name="action">
 
 
 </td>
 </tr>
</table></form>
<?php
break;
}


 require(DIR_WS_INCLUDES . 'footer.php');
  require(DIR_WS_INCLUDES . 'application_bottom.php');
  if (!DB_SHARED) {
    global $database, $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix;
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  }
